﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace _28数据绑定到单个控件
{
    /// <summary>
    /// 必须继承 INotifyPropertyChanged 接口，并实现 PropertyChanged
    /// 通过PropertyChanged将数据暴露给UI
    /// </summary>
    public class Student:INotifyPropertyChanged
    {
        private int _num;
        public int Num
        {
            get { return _num; }
            set {
                _num = value;
                if (PropertyChanged != null)
                    this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Num"));//通过这一句，激发PropertyChanged事件，将数据暴露给UI
            }
        }

        private string _name;
        public string Name
        {
            get { return _name; }
            set { _name = value;
                if (PropertyChanged != null)
                    this.PropertyChanged.Invoke(this, new PropertyChangedEventArgs("Name"));
            }
        }
        /// <summary>
        /// 此事件继承于接口INotifyPropertyChanged
        /// 必须实现
        /// </summary>
        public event PropertyChangedEventHandler PropertyChanged;
    }
}
